package net.wangliping.android.tools;

import android.app.Activity;
import android.content.Intent;
import android.content.res.Resources;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.GridView;
import android.widget.LinearLayout;
import android.widget.AdapterView.OnItemClickListener;

public class MainActivity extends Activity implements OnItemClickListener {

	private LinearLayout mMainLinearLayout;
	private Resources mResources;
	private GridView mToolsGrid;

	private ToolsAdapter mToolsAdapter;

	/** Called when the activity is first created. */
	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.main);

		mMainLinearLayout = (LinearLayout) findViewById(R.id.main_linear_layout);
		ToolUtils.setBackground(this, mMainLinearLayout);

		mToolsGrid = (GridView) findViewById(R.id.grid_tools_icon);
		mToolsGrid.setOnItemClickListener(this);
		mToolsAdapter = new ToolsAdapter(this);

		mResources = getResources();

		if (ToolUtils.getActvityList() == null) {
			ToolUtils.addActivityToMain(
					"net.wangliping.android.tools.microblog.MicroBlog", 
					mResources.getString(R.string.app_microblog_name), R.drawable.icon_microblog);
			
			ToolUtils.addActivityToMain(
					"net.wangliping.android.tools.taskmanager.TaskManager", 
					mResources.getString(R.string.app_taskmanager_name), R.drawable.icon_taskmanager);
		}

		mToolsGrid.setAdapter(mToolsAdapter);
	}

	@Override
	public void onItemClick(AdapterView<?> parent, View view, int position,
			long id) {
		ToolUtils.ActivityInfo info = ToolUtils.getActvityList().get(position);
		String className = info.className;

		Intent intent = new Intent();
		intent.setClassName(this, className);
		startActivity(intent);
	}
}